package
{
	import business.Broker;
	
	import controllers.ModuleController;
	
	import frameworks.models.ModelManager;
	import frameworks.modules.IBaseModule;
	
	import models.Model;

	public class Facade
	{
		private var _modules:Object;
		private var _model:Model;
		private var _modelManager:ModelManager;
		private var _moduleController:ModuleController;
		private var _broker:Broker;
		
		public function Facade(parameter:SingletonEnforcer)
		{
		}
		public function initialization():void{
			_modules = {};
			_broker = new Broker();
			_modelManager = new ModelManager();
			_model = new Model();
			_moduleController = new ModuleController();
		}
		public function get model():Model{return _model;}
		public function get modelManager():ModelManager{return _modelManager;}
		public function get moduleController():ModuleController{return _moduleController;}
		public function get broker():Broker{return _broker;}
		
		public function registerModule(module:IBaseModule):void{
			var id:String = module.id;
			if(_modules[id] != null){throw Error("組件["+id+"]已经存在！");}
			_modules[id] = module;
			module.buildEnvironment();
		}
		public function getModule(id:String):IBaseModule{
			return _modules[id];
		}
		public function getBusinessData(sid:String, ...args):*{
			if(_broker.hasOwnProperty(sid)){
				return broker[sid].apply(null,args);
			}else{
				return void;
			}
		}
		private static var _instance:Facade;
		public static function SingleInstance():Facade{
			if(_instance == null){_instance = new Facade(new SingletonEnforcer());}
			return _instance;
		}
	}
}
class SingletonEnforcer{}